import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Post,
  Req,
  UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Request } from 'express';
import { StartService } from './start.service';
@Controller('start')
export class StartController {
  constructor(private readonly startService: StartService) {}

  @Post()
  @UseGuards(AuthGuard('jwt'))
  create(
    @Body('roomId', ParseIntPipe) roomId: number,
    @Req() request: Request,
  ) {
    let openId = (request.user as { id: string }).id;
    return this.startService.create(roomId, openId);
  }

  @Get()
  @UseGuards(AuthGuard('jwt'))
  findAll(
    @Req()
    request: Request,
  ) {
    let openId = (request.user as { id: string }).id;
    return this.startService.findAll(openId);
  }

  //查询用户收藏房间信息
  @Get('room')
  @UseGuards(AuthGuard('jwt'))
  findStartRoom(
    @Req()
    request: Request,
  ) {
    let openId = (request.user as { id: string }).id;
    return this.startService.findStartRoom(openId);
  }

  @Post('cancel')
  @UseGuards(AuthGuard('jwt'))
  cancelStart(
    @Body('roomId', ParseIntPipe) roomId: number,
    @Req() request: Request,
  ) {
    let openId = (request.user as { id: string }).id;
    return this.startService.cancelStart(roomId, openId);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.startService.remove(+id);
  }
}
